package com.baibei.product.merge;

import android.content.Context;

import com.baibei.basic.BasicPresenterImpl;
import com.baibei.basic.module.observer.PageDataObservable;
import com.baibei.ebec.sdk.ApiFactory;
import com.baibei.ebec.sdk.ITradeApi;
import com.baibei.model.MergeOrderInfo;

import java.util.List;

import io.reactivex.Observable;

/**
 * 拼单
 * Created by ChenRui on 2017/8/15 0015 15:12.
 */
public class MergeOrderPresenterImpl extends BasicPresenterImpl<MergeOrderContract.View> implements MergeOrderContract.Presenter {

    private ITradeApi mTradeApi;
    private PageDataObservable<MergeOrderInfo> mPageObservable;

    public MergeOrderPresenterImpl(Context context, MergeOrderContract.View view) {
        super(context, view);
        mTradeApi = ApiFactory.getInstance().getTradeApi();
        mPageObservable = new PageDataObservable<MergeOrderInfo>(view) {

            @Override
            protected Observable<List<MergeOrderInfo>> onCreateObserver(int page) {
                return mTradeApi.getMergeOrders(page);
            }
        };
    }

    @Override
    public void start() {
        super.start();
        mPageObservable.start();
    }

    @Override
    public void destroy() {
        mPageObservable.destroy();
        super.destroy();
    }

    @Override
    public void loadMore() {
        mPageObservable.loadMore();
    }
}
